import { SSE } from "sse.js";
import * as R from "ramda";

const connect = R.curryN(6, _connect);

function createSSE(
  headers = {},
  onMessage = R.identity,
  onError = R.identity,
  onStatus = R.identity
) {
  return (url, message, method = "GET", _headers = {}) => {
    let sse;
    sse = new SSE(url, {
      headers: R.mergeLeft(_headers, headers),
      payload: message,
      method,
    });
    sse.addEventListener("message", onMessage);
    sse.addEventListener("error", onError);
    sse.addEventListener("status", onStatus);

    return sse;
  };
}
function sendSSE(sse) {
  sse.stream();
}

export { createSSE, sendSSE };
